package com.dd.shop4j.website.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dd.shop4j.goods.model.GoodsInfo;
import com.dd.shop4j.website.goods.service.GoodsInfoService;

@Controller
@RequestMapping("/")
public class HomeController {

	@Resource
	private GoodsInfoService goodsService;
	
	@RequestMapping
	public ModelAndView index() {
		ModelAndView view = new ModelAndView("/website/home");
		view.addObject("items", goodsService.getGoodsInfoByPage(null, 0, 50, null, null));
		return view;
	}
	
	@ResponseBody
	@RequestMapping("/data/{page}")
	public List<GoodsInfo> data(@PathVariable("page") int page) {
		if (page <= 0) {
			page = 1;
		}
		int limit = 50;
		return goodsService.getGoodsInfoByPage(null, (page - 1) * limit, limit, null, null);
	}
	
}
